﻿using System.Collections;
using UnityEngine;
public class ControllerSword : MonoBehaviour
{
    public Material mat;
    public float disolveTime;
    void Start()
    {
        mat.SetFloat("_Disolve", 0);
    }
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            StartCoroutine(StartDisolveForFromCoroutine(6.7f));
        }
        if (Input.GetMouseButtonDown(1))
        {
            StartCoroutine(StartDisolveForFromCoroutine(-0.2f));
        }
    }
    IEnumerator StartDisolveForFromCoroutine(float target)
    {
        float temp = 0;
        float disolve = mat.GetFloat("_Disolve");
        float tempDisolveValue = 0;
        while (temp < disolveTime)
        {
            yield return null;
            tempDisolveValue = Mathf.Lerp(disolve, target, temp / disolveTime);
            temp += Time.deltaTime;
            mat.SetFloat("_Disolve", tempDisolveValue);
        }
    }
}
